package com.yan01.nio;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author yyh
 * @create 2020-10-31 10:02
 */
public class NioFileChannel02 {
    public static void main(String[] args) throws Exception {

        FileInputStream inputStream = new FileInputStream("d:\\12345.txt");

        //通过fileInputStream 获取对应的FileChannel -> 实际类型  FileChannelImpl
        FileChannel channel = inputStream.getChannel();
        //创建缓冲区
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

        //将 通道的数据读入到Buffer
        channel.read(byteBuffer);

        System.out.println(new String(byteBuffer.array()));
        inputStream.close();
    }
}
